import { defineStore, acceptHMRUpdate } from 'pinia'
import { generatorDynamicRouter } from '@/router/generator-routers'
import { constantRouterMap, concatConstantRouterMap } from '@/config/router.config'

export const useMenuStore = defineStore({
    id: 'menu',
    state: () => ({
        menus: [] as any,
        router: [] as any,
    }),
    getters: {
    },
    actions: {
        //   生成路由
        async GenerateRoutes() {
            return generatorDynamicRouter().then((data: any) => {
                this.router = data.find((item: any) => item.path === '/')
                this.menus = concatConstantRouterMap((this.router && this.router.children) || [])
            })
        }
    },
})

if (import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(useMenuStore, import.meta.hot))
}
